//
//  HLVideoGuideContentView.m
//  YueYue
//
//  Created by hulu001 on 2023/6/12.
//

#import "HLVideoGuideContentView.h"

@implementation HLVideoGuideContentView


- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.layer.cornerRadius = 8;
    self.layer.masksToBounds = YES;
    
    self.titleLabel = [UILabel.alloc init];
    self.titleLabel.textColor = [UIColor colorWithRed:251/255.0 green:36/255.0 blue:102/255.0 alpha:1.0];
    self.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    [self addSubview:self.titleLabel];
    
    self.contentLabel = [UILabel.alloc init];
    self.contentLabel.textColor = [UIColor colorWithRed:168/255.0 green:171/255.0 blue:185/255.0 alpha:1.0];
    self.contentLabel.font = [UIFont systemFontOfSize:12];
    self.contentLabel.numberOfLines = 0;
    [self addSubview:self.contentLabel];
    
    self.callButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.callButton.frame = CGRectMake(0, 0, 96, 32);
    self.callButton.layer.cornerRadius = 16;
    self.callButton.layer.masksToBounds = YES;
    self.callButton.backgroundColor = [UIColor colorWithRed:251/255.0 green:27/255.0 blue:94/255.0 alpha:1.0];
    self.callButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.callButton setTitle:@"立即拨打" forState:UIControlStateNormal];
    [self.callButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [self.callButton setImage:[UIImage imageNamed:@"im_video_call"] forState:UIControlStateNormal];
    [self.callButton addTarget:self action:@selector(callEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.callButton];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.titleLabel.frame = CGRectMake(16, 16, self.width - 32, 22);
    self.contentLabel.frame = CGRectMake(16, self.titleLabel.bottom+4, self.titleLabel.width, 36);
    self.callButton.bottom = self.height - 12;
    self.callButton.right = self.width - 13;
}

- (void)refreshData:(HLIMKitMessageModel *)messageModel
{
    [super refreshData:messageModel];
    
    self.bubbleImageView.image = [UIImage imageNamed:@"im_videoguide"];
    
    self.titleLabel.text = @"开启视频聊天";
    self.contentLabel.text = @"视频通话能更快建立彼此之间的联系，快去把握住这次触手可及的缘分～";
    
    
    
    if ([self.callButton.layer animationForKey:@"transform.scale"]) {
        [self.callButton.layer removeAnimationForKey:@"transform.scale"];
    }
    
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
    animation.keyPath = @"transform.scale";
    animation.values = @[@1.0,@1.1,@0.9,@1.05,@0.95,@1.02,@1.0];
    animation.duration = 1;
    animation.calculationMode = kCAAnimationCubic;
    animation.repeatCount = CGFLOAT_MAX;
    [self.callButton.layer addAnimation:animation forKey:@"transform.scale"];
}

- (void)callEvent:(id)sender
{
    [super onTouchUpInside:sender];
}

@end
